package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
    public List<Emp> list(EmpQueryParam empQueryParam);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) values(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void add(Emp emp);

    // 批量删除
    void deleteByIds(List<Integer> ids);

    @Select("select id, username, password, name, gender, phone, job, salary, image, entry_date, create_time, update_time, dept_id from emp where id = #{id}")
    Emp getById(Integer id);

    @MapKey("pos")
    List<Map<String, Object>> countJobEmp();

    @MapKey("name")
    List<Map<String, Object>> countGenderEmp();

    @Select("select id, username, name from emp where username = #{username} and password = #{password}")
    Emp findByUsernameAndPassword(Emp emp);
}
